import 'package:flutter/material.dart';
import 'package:spree/widgets/vip_rectangle_box.dart';
import 'dart:math' as math;

class GamesAuto extends StatefulWidget {
  GamesAuto({Key? key}) : super(key: key);

  @override
  State<GamesAuto> createState() => _GamesAutoState();
}

class _GamesAutoState extends State<GamesAuto> {
  bool _switchSelected = false;
  @override
  Widget build(BuildContext context) {
    return VipRectangleBox(
      padding: EdgeInsets.all(20),
      color: Color(0xFF291F62),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _borderInput(title: 'Number of Bets'),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _borderInput(title: 'Stop the Loss'),
              ),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _switchWithText(
                    title: 'Stop When Winning',
                    openText: 'Reset',
                    closeText: 'Automentor',
                    value: _switchSelected,
                    onChanged: (v) {
                      setState(() {
                        _switchSelected = v;
                      });
                    }),
              ),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _switchWithText(
                    title: 'Stop When Losing',
                    openText: 'Reset',
                    closeText: 'Automentor',
                    value: _switchSelected,
                    onChanged: (v) {
                      setState(() {
                        _switchSelected = v;
                      });
                    }),
              )
            ],
          ),
          Column(
            children: [
              _borderInput(title: 'Number of Bets'),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _borderInput(title: 'Stop the Loss'),
              ),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _borderInput(title: 'Stop the Loss'),
              ),
              Container(
                margin: EdgeInsets.only(top: 20),
                child: _borderInput(title: 'Stop the Loss'),
              ),
            ],
          ),
        ],
      ),
    );
  }

  Border _loutLine() {
    return Border.all(width: 1, color: Color.fromRGBO(255, 255, 255, 0.5));
  }

  Color _whiteColor() {
    return Color(0xFFFFFFFF);
  }

  Widget _borderInput({String? title}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title ?? '',
          style: TextStyle(color: _whiteColor()),
        ),
        Container(
            decoration: BoxDecoration(
              border: _loutLine(),
              borderRadius: const BorderRadius.all(Radius.circular(10.0)),
            ),
            width: 140,
            height: 50,
            padding: EdgeInsets.only(left: 10),
            child: TextField(
              style: TextStyle(color: Colors.white),
              cursorColor: Colors.white,
              decoration: InputDecoration(
                  border: InputBorder.none,
                  hintStyle: TextStyle(
                    color: Color.fromRGBO(255, 255, 255, 0.7),
                  )),
            ))
      ],
    );
  }

  // 开关
  Widget _switchWithText({
    String? title,
    String? openText,
    String? closeText,
    bool value = false,
    required Function onChanged,
  }) {
    return Column(
      // crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title ?? '',
          style: TextStyle(color: _whiteColor()),
        ),
        Padding(
          padding: EdgeInsets.only(top: 10),
          child: Text(
            openText ?? '',
            style: TextStyle(color: _whiteColor()),
          ),
        ),
        Transform.rotate(
          //旋转90度
          angle: -math.pi / 2,
          child: Switch(
            value: value, //当前状态
            onChanged: (v) => {
              //重新构建页面
              onChanged(v)
            },
          ),
        ),
        Padding(
          padding: EdgeInsets.only(bottom: 5),
          child: Text(
            closeText ?? '',
            style: TextStyle(color: _whiteColor()),
          ),
        ),
      ],
    );
  }
}
